/**
 * Created by douxin on 23/09/2016.
 */

import React from 'react';

class RealTimeMsgContainer extends React.Component {

    getUserName() {
        return this.props.data.fans_info.fans_nickname;
    }

    getGoods() {
        return this.props.data.orders.map((v, k) => {
            return `${v.num} 件${v.title}`;
        }).join(', ');
    }

    getChannel() {
        const channels = {
            FIXED: '一口价',
            GIFT: '送礼',
            BULK_PURCHASE: '分销商采购',
            PRESENT: '赠品领取',
            GROUP: '拼团订单',
            COD: '货到付款',
            PEER: '代付',
            QRCODE: '扫码商家二维码直接支付的交易',
            QRCODE_3RD: '线下收银台二维码交易'
        };

        return channels[this.props.data.type];
    }

    getPaymentType() {
        const types = {
            WEIXIN: '微信支付',
            WEIXIN_DAIXIAO: '微信代销',
            ALIPAY: '支付宝',
            BANKCARDPAY: '银行卡',
            PEERPAY: '代付',
            CODPAY: '货到付款',
            BAIDUPAY: '百度钱包',
            PRESENTTAKE: '直接领取赠品',
            COUPONPAY: '优惠券/码全额抵扣',
            BULKPURCHASE: '分销商采购',
            ECARD: '有赞E卡通',
            OTHERS: '其他渠道'
        };

        return types[this.props.data.pay_type];
    }

    getTradeAmount() {
        return parseFloat(this.props.data.total_fee, 0.0);
    }

    getPaymentAmount() {
        return (this.props.data.payment && this.props.data.pay_time) ? parseFloat(this.props.data.total_fee, 0.0): 0.0;
    }

    getNewTradeMsg() {
        return `新订单消息：${this.getUserName()}通过${this.getChannel()}购买了${this.getGoods()}，总金额为 ${this.getTradeAmount()} 元`;
    }

    getPaymentMsg() {
        return `支付消息：${this.getUserName()}通过${this.getPaymentType()}支付金额 ${this.getPaymentAmount()} 元`;
    }

    getNoMsg() {
        return '暂无实时交易消息';
    }

    getMsg() {
        if (this.props.type === 'NewTradeMsg') {
            return this.getNewTradeMsg();
        } else if (this.props.type === 'PaymentMsg') {
            return this.getPaymentMsg();
        } else {
            return this.getNoMsg();
        }
    }

    render() {
        return (
            <div className="row">
                <div className="panel panel-grey-blue">
                    <div className="panel-body msg-container">
                        {this.getMsg()}
                    </div>
                </div>
            </div>
        );
    }

}

RealTimeMsgContainer.propTypes = {
    data: React.PropTypes.object,
    type: React.PropTypes.string
};

export default RealTimeMsgContainer;